#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    int sumofVec(vector<int> &arr)
    {
        int s = 0;
        sort(arr.begin(), arr.end());
        for (int a : arr)
            s += a;
        return s;
    }
    vector<int> fairCandySwap(vector<int> &A, vector<int> &B)
    {
        int delta = sumofVec(B) - sumofVec(A);
        int i = 0, j = 0;
        // b = (2a + sB - sA)/2;
        for (i = 0; i < A.size(); ++i)
        {
            if (binary_search(B.begin(), B.end(), (2 * A[i] + delta) / 2) == true)
                return {A[i], (2 * A[i] + delta) / 2};
        }
        return {};
    }
};